package com.example.demo.mapper;

import com.example.demo.dto.SelectedStudentRequestDTO;
import com.example.demo.mapper.entity.Ad;
import com.example.demo.mapper.entity.AdKey;
import com.example.demo.mapper.entity.AdStudent;
import com.example.demo.mapper.entity.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
@Repository
public interface AdManageMapper {
    @Insert("INSERT INTO ad (advertiser_id, title, description, image_url," +
            "start_time, end_time, ad_type, ad_status, create_time, update_time," +
            "user_id, detail_url) " +
            "VALUES (#{advertiserId}, #{title}, #{description}, #{imageUrl}," +
            "#{startTime}, #{endTime}, #{adType}, #{adStautus}, #{createTime}, #{updateTime}," +
            "#{userId}, #{detailUrl}) " )
    @Options(useGeneratedKeys = true, keyProperty = "adId", keyColumn = "ad_id")
    int insertAd(Ad currentAd);

    @Insert("INSERT INTO ad_key (ad_id, gender, native_place, college_id) " +
            "VALUES (#{adId}, #{gender}, #{nativePlace}, #{collegeId}) " )
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insertAdKey(AdKey currentAdKey);

    @Select("select * from student where native_place = #{nativePlace} AND college_id = #{collegeId} AND gender = #{gender}")
    List<Student> getStudentList(Student student);

    @Insert("INSERT INTO ad_student (ad_id, student_id,priority) " +
            "VALUES (#{adId}, #{studentId}, #{priority}) " )
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int addStudentAd(AdStudent adStudent);

    @Select("SELECT COUNT(*) FROM student where native_place = #{nativePlace} AND college_id = #{collegeId} AND gender = #{gender}")
    int getTotalStudent(SelectedStudentRequestDTO studentData);

    @Select("SELECT COUNT(*) FROM student where native_place = #{nativePlace} AND college_id = #{collegeId}")
    int getTotalStudent1(SelectedStudentRequestDTO studentData);

    @Select("SELECT COUNT(*) FROM student where native_place = #{nativePlace}")
    int getTotalStudent2(SelectedStudentRequestDTO studentData);

    @Select("SELECT COUNT(*) FROM student where native_place = #{nativePlace} AND gender = #{gender}")
    int getTotalStudent3(SelectedStudentRequestDTO studentData);

    @Select("SELECT COUNT(*) FROM student where college_id = #{collegeId} AND gender = #{gender}")
    int getTotalStudent4(SelectedStudentRequestDTO studentData);

    @Select("SELECT COUNT(*) FROM student where college_id = #{collegeId}")
    int getTotalStudent5(SelectedStudentRequestDTO studentData);

    @Select("SELECT COUNT(*) FROM student where gender = #{gender}")
    int getTotalStudent6(SelectedStudentRequestDTO studentData);




}
